/**
 * 
 */
package jp.seraph.jspf.utils;

import java.util.HashMap;
import java.util.Map;

import jp.seraph.jsade.math.Angle;
import jp.seraph.jsade.model.Align;
import jp.seraph.jsade.model.JointIdentifier;
import jp.seraph.jsade.model.nao.NaoJointIdentifier;

/**
 * 
 */
public class NaoSymmetricJointContext implements SymmetricJointContext {

    private static Map<JointIdentifier, Boolean> MIRROR_MINUS_MAP;
    private static Map<JointIdentifier, JointIdentifier> MIRROR_IDENTIFIER_MAP;
    private static Map<JointIdentifier, Align> ALIGN_MAP;

    static {
        MIRROR_IDENTIFIER_MAP = new HashMap<JointIdentifier, JointIdentifier>();
        MIRROR_MINUS_MAP = new HashMap<JointIdentifier, Boolean>();
        ALIGN_MAP = new HashMap<JointIdentifier, Align>();

        for (NaoJointIdentifier tIdentifier : NaoJointIdentifier.getIdentifiers()) {
            MIRROR_IDENTIFIER_MAP.put(tIdentifier, tIdentifier.getMirrorIdentifier());
            ALIGN_MAP.put(tIdentifier, tIdentifier.getAlign());
            MIRROR_MINUS_MAP.put(tIdentifier, tIdentifier.shouldMinusAsMirror());
        }
    }

    /**
     * 
     * @see jp.seraph.jspf.utils.SymmetricJointContext#getSymmetricAngle(jp.seraph.jsade.model.JointIdentifier,
     *      jp.seraph.jsade.math.Angle)
     */

    public Angle getSymmetricAngle(JointIdentifier aIdentifier, Angle aAngle) {
        return MIRROR_MINUS_MAP.get(aIdentifier) ? aAngle.minus() : aAngle;
    }

    /**
     * 
     * @see jp.seraph.jspf.utils.SymmetricJointContext#getSymmetricIdentifier(jp.seraph.jsade.model.JointIdentifier)
     */

    public JointIdentifier getSymmetricIdentifier(JointIdentifier aIdentifier) {
        return MIRROR_IDENTIFIER_MAP.get(aIdentifier);
    }

    /**
     * 
     * @see jp.seraph.jspf.utils.SymmetricJointContext#isCenter(jp.seraph.jsade.model.JointIdentifier)
     */

    public boolean isCenter(JointIdentifier identifier) {
        return ALIGN_MAP.get(identifier) == Align.CENTER;
    }

    /**
     * 
     * @see jp.seraph.jspf.utils.SymmetricJointContext#isLeft(jp.seraph.jsade.model.JointIdentifier)
     */

    public boolean isLeft(JointIdentifier identifier) {
        return ALIGN_MAP.get(identifier) == Align.LEFT;
    }

    /**
     * 
     * @see jp.seraph.jspf.utils.SymmetricJointContext#isRight(jp.seraph.jsade.model.JointIdentifier)
     */

    public boolean isRight(JointIdentifier identifier) {
        return ALIGN_MAP.get(identifier) == Align.RIGHT;
    }

}
